<template>
  <el-dialog title="复用测评项" :close-on-click-modal="false" :visible.sync="visible" width="800px">
    <el-container>
      <el-main style="max-height:60vh">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="140px">
          <el-form-item label="测评项统称" prop="xmName">
            <el-input v-model="dataForm.xmName" placeholder="测评项统称" style="width:90%;"></el-input>
          </el-form-item>
          <el-form-item label="应用状态" prop="yyFw">
            <el-select v-model="dataForm.yyFw" placeholder="请选择应用状态" style="width:90%;">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </el-main>
    </el-container>
    <span slot="footer" class="dialog-footer">

      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
      <el-button type="primary" plain @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/*!
 * 绩效考核-评分项目管理编辑
 *
 * @author zmk
 * @date 2021-06-16 10:11:35
 */
import { getObj, addObj, putObj, addmultiplexing } from '@/api/ceping/cepingxmxxb'

export default {
  data() {
    return {
      visible: false,
      canSubmit: false,
      options: [{
        value: '个性',
        label: '个性'
      }, {
        value: '通用',
        label: '通用'
      }],
      dataForm: {
        id: 0,
        xmName: '',
        yyFw: ''
      },
      dataRule: {
        xmName: [
          { required: true, message: '项目名称不能为空', trigger: 'blur' }
        ],
        yyFw: [
          { required: true, message: '应用状态不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.canSubmit = true;
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          getObj(this.dataForm.id).then(response => {
            this.dataForm = response.data.data
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.canSubmit = false;

          addmultiplexing(this.dataForm).then(data => {
            this.$notify.success('复用成功')
            this.visible = false
            this.$emit('refreshDataList')
          }).catch(() => {
            this.canSubmit = true;
          });
        }
      })
    }
  }
}
</script>
